﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DataManager;
using StoreClientModule;
namespace MBB_Store_Sales_Report
{
    public partial class frmCheckStatusEntry : Form
    {

        ChequeRecords cr = new ChequeRecords();
        DataTable RecordTable = new DataTable();
        ChequeEntryCommit cec = new ChequeEntryCommit();

        public frmCheckStatusEntry()
        {
            InitializeComponent();
            btnClose.Click += new EventHandler(btnClose_Click);
            panel2.EnabledChanged += new EventHandler(panel2_EnabledChanged);
            btnUpdate.Click += new EventHandler(btnUpdate_Click);
            btnRefresh.Click += new EventHandler(btnRefresh_Click);
            cr.ProcessError += new ChequeRecords.MyEventHandler(cr_ProcessError);
            cr.ProcessCompleted += new ChequeRecords.MyEventHandler(cr_ProcessCompleted);
        }

        void btnRefresh_Click(object sender, EventArgs e)
        {
            cr.GetRecords();
        }

        void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtCheckNumber.Text != "" && txtStatus.Text != "")
            {
                cec.checkNumber = txtCheckNumber.Text;
                cec.status = txtStatus.Text;

                cr.UpdateStatus(cec);
            }
            
        }

        void cr_ProcessCompleted(string msg)
        {
            uCoreClasses.uThreader t = new uCoreClasses.uThreader();
            t.SafeCall(this, delegate
            {
                if (cr.ProcessCode == 1)
                {
                    RecordTable = cr.RecordTable;
                    grd.DataSource = RecordTable;
                    
                }
                if (cr.ProcessCode == 5)
                {
                    if (cr.Updated == false)
                    {
                        MessageBox.Show("Update is not successful... Check Number not Existing");

                    }
                    else
                    {
                        MessageBox.Show("Status Updated Thank you");
                        txtCheckNumber.Text = "";

                    }
                }

            });
        }
        void cr_ProcessError(string msg)
        {
            uCoreClasses.uThreader t = new uCoreClasses.uThreader();
            t.SafeCall(this, delegate
            {
                MessageBox.Show(msg);
            });
        }

        

        void panel2_EnabledChanged(object sender, EventArgs e)
        {
            if (!panel2.Enabled)
            {
                panel2.BackColor = Color.MidnightBlue;
            }
            else
            {
                panel2.BackColor = Color.RoyalBlue;
            }
        }
        void btnClose_Click(object sender, EventArgs e)
        {
            pnlExpensesEntry.Dispose();
            this.Dispose();
        }
        public Panel PanelForm
        {
            get { return pnlExpensesEntry; }
        }
        public void Initialize(string Title)
        {
            this.Select();
            lblText.Text = Title;
            cr.GetRecords();
        }

      
    }
}
